package com.zxy.hotel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxy.hotel.entity.Room;
import com.zxy.hotel.mapper.RoomMapper;
import com.zxy.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jiusi
 * @since 2021-12-12
 */
@Service
public class RoomServiceImpl extends ServiceImpl<RoomMapper, Room> implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public List<Room> getRoomList(String type) {
        if (!StringUtils.hasText(type)) {
            return list();
        } else if ("single".equals(type)) {
            return roomMapper.getSingleRoomList();
        } else if ("double".equals(type)) {
            return roomMapper.getDoubleRoomList();
        } else if ("more".equals(type)) {
            return roomMapper.getMoreRoomList();
        }
        return null;
    }

    @Override
    public Map<String, Integer> getRoomCount() {
        QueryWrapper<Room> queryWrapper = new QueryWrapper<>();
        Integer totalCount = roomMapper.selectCount(queryWrapper);
        queryWrapper.eq("status", "空闲");
        Integer freeCount = roomMapper.selectCount(queryWrapper);
        HashMap<String, Integer> map = new HashMap<>();
        map.put("totalCount", totalCount);
        map.put("freeCount", freeCount);
        map.put("hasCount", totalCount - freeCount);
        return map;
    }
}
